<template>
<div style="width: 100%;height: 100%;background-color: #fff; overflow: hidden">
  <div class="findPassword">
    <div class="box">
      <div class="int_num" :class="bottomSolid1?'active':''">
        <input type="tel" v-model="tel" @focus="bottomSolid1 = true" @blur="bottomSolid1 = false" placeholder="请输入手机号">
        <div data-v-dd658fba="" class="getCAPTCHA" id="sms" @click="getSms">
          {{txt}}
        </div>
      </div>
      <div class="int_num" :class="bottomSolid2?'active':''">
        <input type="text" v-model="sms" @focus="bottomSolid2 = true" @blur="bottomSolid2 = false" placeholder="请输入验证码">
      </div>
      <div class="int_num" :class="bottomSolid3?'active':''">
        <form>
          <input type="password" v-model="password" @focus="bottomSolid3 = true" autocomplete="off" @blur="bottomSolid3 = false" placeholder="请输入密码">
        </form>
      </div>
    </div>

    <div class="login-btn" @click="getPass">确定</div>
  </div>
</div>
</template>

<script>
import {sendSMS,getPass} from '../../utils/api'
import {Toast} from "vant";
export default {
  name: "set-new-pass",
  data(){
    return{
      bottomSolid1: false,
      bottomSolid2: false,
      bottomSolid3: false,
      txt:'获取验证码',
      num:10,
      tel:'',
      sms:'',
      password:''
    }
  },
  methods:{
    getSms(){
      const phoneReg = /^(1[356789]|9[28])\d{9}$/;
      let obj = {
        mobile: this.tel,
        sms_type:'getPassword'
      }
      if(!phoneReg.test(this.tel)){
        Toast('请输入正确的手机号')
      }else {
        let clock = setInterval(() => {
          if (this.num > 0) {
            // this.num--
            // console.log(this.num + "s后重新发送")
            this.txt = "获取验证码(" + this.num-- + ")"
            document.getElementById("sms").style.color = "rgb(204, 204, 204)";
          } else {
            window.clearInterval(clock)
            this.txt = "获取验证码"
            document.getElementById("sms").style.color = "#e60012";
          }
        }, 1000)
        sendSMS(obj).then(res=>{
          console.log(res)
        })
        Toast('验证码已发送')
      }
    },
    //确认修改验证码
    getPass(){
      let obj = {
        mobile: this.tel,
        password: this.password,
        sms_code: this.sms
      }
      // console.log(obj)
      if(this.tel){
        if(this.sms){
          if(this.password){
            getPass(obj).then(res=>{
              console.log(res)
              if(res.code === 200){
                Toast.success(res.msg)
                let o = setInterval(() => {
                  window.clearInterval(o)
                  this.$router.replace('/options')
                  // this.$router.push('/options')//配置路由 push 代替replace
                }, 1000)
              }else {
                Toast.fail(res.msg)
              }
            })
          }else{
            Toast.fail('请输入密码')
          }
        }else {
          Toast.fail('请输入验证码')
        }
      }else {
        Toast.fail('请输入手机号')
      }
    }
  }
}
</script>

<style scoped lang="scss">
.box {
  margin-top: 5px;
  padding: 0 20px;
  .int_num{
    //height: 50px;
    border-bottom: 1px solid #f1f1f1;
    input {
      border: 0;
      width: 168px;
      line-height: 20px;
      padding: 15px 0;
      font-size: 15px;
      font-weight: 500;
    }
    input::-webkit-input-placeholder {
      color: #b7b7b7;
      font-size: 15px;
      font-weight: 500;
    }
    .getCAPTCHA {
      float: right;
      margin-top: 12.5px;
      margin-right: 5px;
      height: 25px;
      line-height: 25px;
      color: #e60012;
      font-weight: 500;
    }
  }
}
.login-btn {
  width: 280px;
  height: 50px;
  margin: 40px auto !important;
  // border: solid 1px;
  border-radius: 4px;
  text-align: center;
  line-height: 50px;
  background-image: linear-gradient(to right, #ec7f7f, #e60618);
  color: #fff;
  box-shadow: 0 10px 12px 6px rgba(250, 207, 211, 0.68);
  font-size: 16px;
  font-weight: 500;
}
.active {
  border-bottom: 1px solid #e60012 !important;
}
</style>